home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / x25 / nrs.shar.Z / nrs.shar / simple.awk < prev    next >
Encoding:
AWK Script  |  1990-04-27  |  3.1 KB  |  101 lines

  1. #! /bin/awk -f
  2. #
  3. # RCSid[] = "@(#)$Header: simple.awk,v 3.0 86/09/26 10:13:31 pb Rel $"
  4. #
  5. #    squash up the output from nrs into smaller form
  6. #    for new-format york directory
  7. #
  8. BEGIN { FS = ":" ; isunix = "UNSET" }
  9. {    # if it's ANOTHER VALID FIELD for the same place, add service
  10.     if ( NF==8 && (isunix==$1 || isunix=="0" || $1=="0") && \
  11.          network==$2 && name==$4 && (addr==$5 || addr=="" || $5=="") && \
  12.          strip==$6)
  13.     {
  14.         # we ought to do ``isunix |= $1'', but not in awk we can't
  15.         # SO: approximate: We know ((x | 0) == x) ......
  16.         if (isunix=="0") isunix = $1;
  17.  
  18.         if ( split($3, ar, "|") == 1)
  19.             revservice    = revservice ar[1];
  20.         else    revservice    = revservice ar[2];
  21.         service = service ar[1];
  22.  
  23.         if (addr == "") addr = $5;
  24.  
  25.         if ($7 != "")
  26.         {    if (values == "")    values = $7;
  27.             else            values = values "|" $7;
  28.         }
  29.  
  30.         if ($8 != "")
  31.         {    text = text "|" $8;
  32.             n = split(text, ar, "|");
  33.             for (i=1; i<n; i++)
  34.                 for (j=i+1; j<=n; j++)
  35.                     if (ar[i] == ar[j]) ar[j] = "";
  36.             text = ""
  37.             for (i=1; i<=n; i++) if (ar[i] != "")
  38.             {    if (text == "") text = ar[i];
  39.                 else        text = text "|" ar[i];
  40.             }
  41.         }
  42.     }
  43.     else                # First write out pending (if any)
  44.     {    if (isunix != "UNSET")
  45.         {
  46.             if (service ~ /t/ && service ~ /f/ && service ~ /m/)
  47.              {    split(service, ar, "t"); service = ""
  48.             for (elem in ar) service = service ar[elem]
  49.                  split(service, ar, "f"); service = ""
  50.             for (elem in ar) service = service ar[elem]
  51.                  split(service, ar, "m"); service = ""
  52.             for (elem in ar) service = service ar[elem]
  53.             service = "Y" service
  54.              }
  55.              if (service ~ /Y/ && service ~ /x/)
  56.              {    split(service, ar, "Y"); service = ""
  57.             for (elem in ar) service = service ar[elem]
  58.                  split(service, ar, "x"); service = ""
  59.             for (elem in ar) service = service ar[elem]
  60.             service = "X" service
  61.              }
  62.  
  63.             if (revservice ~ /t/ && revservice ~ /f/ && revservice ~ /m/)
  64.              {    split(revservice, ar, "t"); revservice = ""
  65.             for (elem in ar) revservice = revservice ar[elem]
  66.                  split(revservice, ar, "f"); revservice = ""
  67.             for (elem in ar) revservice = revservice ar[elem]
  68.                  split(revservice, ar, "m"); revservice = ""
  69.             for (elem in ar) revservice = revservice ar[elem]
  70.             revservice = "Y" revservice
  71.              }
  72.              if (revservice ~ /Y/ && revservice ~ /x/)
  73.              {    split(revservice, ar, "Y"); revservice = ""
  74.             for (elem in ar) revservice = revservice ar[elem]
  75.                  split(revservice, ar, "x"); revservice = ""
  76.             for (elem in ar) revservice = revservice ar[elem]
  77.             revservice = "X" revservice
  78.              }
  79.              # If identical, then merge ....
  80.              if ( service != revservice )
  81.                 service = service "|" revservice;
  82.              print isunix":"network":"service":"name":"addr":"strip":"values":"text
  83.         }
  84.         if (NF == 8)        # if valid, save the info
  85.         {    isunix    = $1; network    = $2
  86.             name    = $4; addr    = $5 "";
  87.             strip    = $6; values    = $7; text    = $8
  88.             if ( split($3, ar, "|") == 1)
  89.                 revservice    = ar[1];
  90.             else    revservice    = ar[2];
  91.             service = ar[1];
  92.         }
  93.         else            # invalid: just print it asis
  94.         {    print $0;     isunix = "UNSET"
  95.         }
  96.     }
  97. }
  98. END { if ( isunix != "UNSET" )        # Flush any pending data
  99.     print isunix":"network":"service"|"revservice":"name":"addr":"strip":"values":"text
  100. }
  101.